﻿<Window x:Class="SeriesEpisodeMapper.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:conv="clr-namespace:SeriesEpisodeMapper.Converters"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:vw="clr-namespace:SeriesEpisodeMapper.Views"
        xmlns:cutil_ctrl="clr-namespace:CommonUtilities.Controls;assembly=CommonUtilities"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="950"
        Title="Series-Episode Mapper" Icon="/SeriesEpisodeMapper;component/Images/s01e01.png" 
        WindowStartupLocation="CenterScreen" WindowState="Normal" WindowStyle="None" ResizeMode="NoResize">
    <!--Height="350" Width="1000"-->
    <Window.Resources>
        <!--<conv:FilePathValidator x:Key="FilePathValidator" /> RKD -->
        <conv:ToolTipWhenConverter x:Key="ToolTipWhenConverter" />
    </Window.Resources>

    <xctk:BusyIndicator IsBusy="{Binding IsBusy}">
        <Grid Margin="5">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="300" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <cutil_ctrl:CUtil_TitleBar Name="cutilTitleBar" Grid.ColumnSpan="2" Margin="-5,-5,-5,3" HorizontalAlignment="Stretch" 
                                       MouseLeftButtonDown="CUtil_TitleBar_MouseLeftButtonDown" />

            <Border Grid.Row="1" BorderBrush="Purple" BorderThickness="2,2,1,1" CornerRadius="5,0,0,0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <UniformGrid Margin="5,3" Height="25" Columns="2">
                        <Button Name="btnBrowseSource" Content="Browse source.." Style="{StaticResource ButtonStyleLeft}" 
                                Command="{Binding BrowseSourceCommand}">
                            <Button.ToolTip>
                                <StackPanel>
                                    <TextBlock Text="Browse source file.." />
                                    <TextBlock Text="{Binding SourceFileInfo.FileExtn, StringFormat='Extn: {0}', FallbackValue=NA}" 
                                           Visibility="{Binding SourceFileInfo, Converter={StaticResource ToolTipWhenConverter}}" />
                                    <TextBlock Text="{Binding SourceFileInfo.FileName, StringFormat='Name: {0}', FallbackValue=NA}" 
                                           Visibility="{Binding SourceFileInfo, Converter={StaticResource ToolTipWhenConverter}}" />
                                    <TextBlock Text="{Binding SourceFileInfo.FileFolder, StringFormat='Folder: {0}', FallbackValue=NA}" 
                                           Visibility="{Binding SourceFileInfo, Converter={StaticResource ToolTipWhenConverter}}" />
                                </StackPanel>
                            </Button.ToolTip>
                        </Button>
                        <Button Name="btnBrowseSeriesMap" Content="Broswe series-path.." Style="{StaticResource ButtonStyleRight}" 
                            Command="{Binding BrowseSeriesPathCommand}">
                            <Button.ToolTip>
                                <StackPanel>
                                    <TextBlock Text="Browse source file.." />
                                    <TextBlock Text="{Binding SeriesPathFileInfo.FileExtn, StringFormat='Extn: {0}', FallbackValue=NA}" 
                                           Visibility="{Binding SeriesPathFileInfo, Converter={StaticResource ToolTipWhenConverter}}" />
                                    <TextBlock Text="{Binding SeriesPathFileInfo.FileName, StringFormat='Name: {0}', FallbackValue=NA}" 
                                           Visibility="{Binding SeriesPathFileInfo, Converter={StaticResource ToolTipWhenConverter}}" />
                                    <TextBlock Text="{Binding SeriesPathFileInfo.FileFolder, StringFormat='Folder: {0}', FallbackValue=NA}" 
                                           Visibility="{Binding SeriesPathFileInfo, Converter={StaticResource ToolTipWhenConverter}}" />
                                </StackPanel>
                            </Button.ToolTip>
                        </Button>
                    </UniformGrid>

                    <StackPanel Grid.Row="1">
                        <Border Margin="5,3" BorderBrush="Purple" BorderThickness="2" CornerRadius="8,0,8,0">
                            <vw:DelimeterSelector DataContext="{Binding DelimeterSettings}" />
                        </Border>

                        <Border Margin="5,3" BorderBrush="Purple" BorderThickness="2" CornerRadius="8,0,8,0">
                            <ItemsControl Name="itmctrlMapper" ItemsSource="{Binding MapFields}" IsEnabled="{Binding IsMapLoaded}">
                                <ScrollBarVisibility />
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border Margin="5,3" Padding="3" BorderBrush="LightGray" BorderThickness="1" CornerRadius="8,0,8,0">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition />
                                                    <ColumnDefinition />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>

                                                <TextBlock Text="{Binding TargetPropertyDisplay, Mode=OneTime, FallbackValue=PropertyName}" TextAlignment="Right" Margin="2,1,3,1" />
                                                <ComboBox Grid.Column="1" Grid.ColumnSpan="2" SelectedItem="{Binding SelectedSourceField, Mode=TwoWay}"
                                                      ItemsSource="{Binding DataContext.SourceFields, RelativeSource={RelativeSource AncestorType=ItemsControl}}">
                                                    <ComboBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <TextBlock Text="{Binding }" />
                                                        </DataTemplate>
                                                    </ComboBox.ItemTemplate>
                                                    <ComboBox.ToolTip>
                                                        <TextBlock Text="{Binding SelectedSourceField}" />
                                                    </ComboBox.ToolTip>
                                                </ComboBox>
                                            </Grid>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Border>

                        <UniformGrid Margin="5,3" Height="25" Columns="2">
                            <Button Name="btnSaveMap" Content="Save map" Style="{StaticResource ButtonStyleLeft}" Command="{Binding SaveMapCommand}">
                                <Button.ToolTip>
                                    <TextBlock Text="Save field mapping" />
                                </Button.ToolTip>
                            </Button>
                            <Button Name="btnClear" Content="Clear" Style="{StaticResource ButtonStyleRight}" Command="{Binding ClearMapCommand}">
                                <Button.ToolTip>
                                    <TextBlock Text="Clear all field mappings, delimeter settings and episode data" />
                                </Button.ToolTip>
                            </Button>
                        </UniformGrid>

                        <Border Margin="5,3" BorderBrush="Purple" BorderThickness="2" CornerRadius="8,0,8,0">
                            <Grid Grid.Row="4" Margin="5,3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="Auto">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <Button Name="btnSelectTarget" Grid.Row="1" Grid.ColumnSpan="3" Margin="5,3" Padding="25,3" 
                                        Content="Load/Select target.." HorizontalAlignment="Stretch" 
                                        Style="{StaticResource ButtonStyleSingle}" Command="{Binding SelectTargetCommand}">
                                    <Button.ToolTip>
                                        <StackPanel>
                                            <TextBlock Text="Load/Select target directory..&#10;(Ctrl+Click to select manually)" />
                                            <TextBlock Text="{Binding TargetDirectory, StringFormat='Folder: {0}', FallbackValue=NA}" 
                                                       Visibility="{Binding TargetDirectory, Converter={StaticResource ToolTipWhenConverter}}" />
                                        </StackPanel>
                                    </Button.ToolTip>
                                </Button>

                                <Grid Grid.Row="0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <CheckBox Name="chkSelectSeries" Grid.Column="0" Margin="5,3" VerticalAlignment="Center" IsChecked="{Binding IsSingleSeries, Mode=TwoWay}" />
                                    <TextBlock Name="txtbSeriesSelectInfo" Grid.Column="1" Margin="5,3,0,3" VerticalAlignment="Center" Text="Select a series:" />
                                    <ComboBox Name="cmbSeriesSelector" Grid.Column="2" Margin="5,3" HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                              IsEnabled="{Binding ElementName=chkSelectSeries, Path=IsChecked}" 
                                              ItemsSource="{Binding AllSeries}" SelectedItem="{Binding SelectedSeries}"
                                              DisplayMemberPath="SeriesTitle" SelectedValuePath="SeriesTitle" />
                                </Grid>

                                <Button Grid.Row="2" Grid.Column="3" Margin="5,3" Padding="8,1" VerticalAlignment="Center" VerticalContentAlignment="Center"  
                                    Content="Load files" IsEnabled="False" Visibility="Collapsed" Command="{Binding LoadFileCommand}" />
                            </Grid>
                        </Border>
                    </StackPanel>
                </Grid>
            </Border>

            <Border Grid.Row="1" Grid.Column="1" BorderBrush="Purple" BorderThickness="1,2,2,1" CornerRadius="0,5,0,0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>

                    <Grid Grid.Row="0" Margin="5,3" Height="25">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <UniformGrid Columns="3" HorizontalAlignment="Stretch">
                            <Button Background="LightPink" Style="{StaticResource ButtonStyleLeft}" 
                                    Content="Generate file names" Command="{Binding GenerateFileNameCommand}">
                                <Button.ToolTip>
                                    <TextBlock Text="Generate file names" />
                                </Button.ToolTip>
                            </Button>
                            <Button Background="LightBlue" Style="{StaticResource ButtonStyleMid}" 
                                    Content="Link files" Command="{Binding LinkFileCommand}">
                                <Button.ToolTip>
                                    <TextBlock Text="Link files" />
                                </Button.ToolTip>
                            </Button>
                            <Button Background="LightGreen" Style="{StaticResource ButtonStyleMid}" 
                                    Content="Rename files" Command="{Binding RenameFileCommand}">
                                <Button.ToolTip>
                                    <TextBlock Text="Rename files" />
                                </Button.ToolTip>
                            </Button>
                        </UniformGrid>
                        <Button Grid.Column="1" Padding="10,0" Foreground="Red" FontWeight="Bold" 
                                Style="{StaticResource ButtonStyleMid}" 
                                Content="Revert back" Command="{Binding RevertBackCommand}">
                            <Button.ToolTip>
                                <TextBlock Foreground="Red" Text="Revert back file names (to be used only for test)" />
                            </Button.ToolTip>
                        </Button>
                        <Button Grid.Column="2" Padding="10,0" Foreground="Red" FontWeight="Bold" 
                                Style="{StaticResource ButtonStyleRight}" 
                                Content="Quit" Command="{Binding QuitAppCommand}">
                            <Button.ToolTip>
                                <TextBlock Foreground="Red" Text="Quit application!" />
                            </Button.ToolTip>
                        </Button>
                    </Grid>

                    <DataGrid Name="dgEpisodeInfo" Grid.Row="1" Margin="5,3,5,5" VerticalAlignment="Stretch" FrozenColumnCount="3"
                              AutoGenerateColumns="False" AlternatingRowBackground="LightGray"
                              ItemsSource="{Binding AllEpisodes}" CanUserResizeColumns="False" 
                              CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="False">
                        <DataGrid.Background>
                            <ImageBrush ImageSource="/SeriesEpisodeMapper;component/Images/s01e01.png" 
                                        Stretch="Fill" TileMode="Tile" Viewport="0,0,115.985497486641,93.3216646444235" 
                                        ViewportUnits="Absolute" Opacity="0.1" />
                        </DataGrid.Background>
                        <DataGrid.Columns>
                            <DataGridTemplateColumn Header="TV Series" IsReadOnly="True">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding SeriesTitle}" Background="{Binding SeriesBackColour}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTextColumn Binding="{Binding SeasonIndex}" Header="S#" IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding EpisodeIndex}" Header="E#" IsReadOnly="True" />
                            <DataGridTemplateColumn Header="Title">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding EpisodeTitle}" Background="{Binding BackColour}">
                                            <TextBlock.ToolTip>
                                                <TextBlock Text="{Binding InfoTip, StringFormat='Hint: {0}'}" />
                                            </TextBlock.ToolTip>
                                        </TextBlock>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTemplateColumn IsReadOnly="True">
                                <DataGridTemplateColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <Label Content="Possible File Name" Background="LightPink">
                                            <Label.ToolTip>
                                                <TextBlock Text="File name on disk&#10;(s##e## format)" />
                                            </Label.ToolTip>
                                        </Label>
                                    </DataTemplate>
                                </DataGridTemplateColumn.HeaderTemplate>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding SEIndex}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTemplateColumn IsReadOnly="True">
                                <DataGridTemplateColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <Label Content="Formatted Name" Background="LightPink" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.HeaderTemplate>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding FileNameFormatted}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTemplateColumn IsReadOnly="True">
                                <DataGridTemplateColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <Label Content="Parent Folder" Background="LightBlue" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.HeaderTemplate>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding ParentFolder}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTemplateColumn IsReadOnly="True">
                                <DataGridTemplateColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <Label Content="Parent Folder&#10;(SeriesPath)" Background="LightBlue" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.HeaderTemplate>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding SeriesPath}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridTemplateColumn IsReadOnly="True">
                                <DataGridTemplateColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <Label Content="Extns" Background="LightBlue" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.HeaderTemplate>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding AllExtnsText}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            <DataGridCheckBoxColumn Binding="{Binding IsConverted}" IsReadOnly="True">
                                <DataGridCheckBoxColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <Label Content="Converted?" Background="LightGreen" />
                                    </DataTemplate>
                                </DataGridCheckBoxColumn.HeaderTemplate>
                            </DataGridCheckBoxColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </Grid>
            </Border>

            <Border Grid.Row="2" Grid.ColumnSpan="2" Margin="0,5,0,0" Background="#FFE5A4DD" BorderBrush="Purple" BorderThickness="2,1,2,2" CornerRadius="0,0,5,5">
                <StatusBar Grid.Row="2" Grid.ColumnSpan="2" Margin="2,0"  Height="30" Background="#FFE5A4DD" />
            </Border>
        </Grid>
    </xctk:BusyIndicator>
</Window>
